import request from '@/utils/http'

//走mock数据
import userMock from '@/mock/mockdata/userMock'
import { useUserStore } from '@/store/modules/user'
import { isMockEnabled } from '@/utils/http/mock'

/**
 * 登录
 * @param params 登录参数
 * @returns 登录响应
 */
export function fetchLogin(params: Api.Auth.LoginParams) {
  if (isMockEnabled()) {
    return userMock.mockLogin(params).then((res) => res.data)
  }
  return request.get<Api.Auth.LoginResponse>({
    url: '/mem/loginForPwd',
    params
  })
}

/**
 * 获取用户信息
 * @returns 用户信息
 */
export function fetchGetUserInfo() {
  if (isMockEnabled()) {
    const { accessToken } = useUserStore()
    // mock 返回的是 { code, msg, data }，这里取 data 给业务用
    return userMock.mockGetUserInfo(accessToken).then((res) => res.data)
  }
  return request.get<Api.Auth.UserInfo>({
    url: '/mem/getMember'
  })
}

//获得学生相关信息
export function studentInfo(params: {
  university: string
  school?: string
  major?: string
  grade?: string
}) {
  if (isMockEnabled()) {
    // mock 返回的是 { code, msg, data }，这里取 data 给业务用
    return userMock.mockGetStudentPortrait(params).then((res) => res.data)
  }
  return request.get<Api.Auth.UserInfo>({
    url: '/mem/getMember',
    params
  })
}

//获取工作台的学校整体数据
export function schoolTotal() {
  if (isMockEnabled()) {
    // mock 返回的是 { code, msg, data }，这里取 data 给业务用
    return userMock.mockGetSchoolTotal().then((res) => res.data)
  }
  return request.get<Api.Auth.UserInfo>({
    url: '/mem/getMember'
  })
}

//获取学校学院，专业，年级
export function schoolStructure(params: { university: string }) {
  if (isMockEnabled()) {
    // mock 返回的是 { code, msg, data }，这里取 data 给业务用
    return userMock.mockGetSchoolStructure(params).then((res) => res.data)
  }
  return request.get<Api.Auth.UserInfo>({
    url: '/mem/getMember',
    params
  })
}

//获取就业数据分析
export function employmentDataAnalysis(params: {
    university: string
    school?: string
    major?: string
    grade?: string
  }) {
    if (isMockEnabled()) {
      // mock 返回的是 { code, msg, data }，这里取 data 给业务用
      return userMock.mockEmploymentDataAnalysis(params).then((res) => res.data)
    }
    return request.get<Api.Auth.UserInfo>({
      url: '/mem/getMember',
      params
    })
}